********************************************************************************
****************** Step 2:  Unemployment and the left-wing advantage************
********************************************************************************
*** This is the code to create the result presented in Appendix G and the summary statistics presented in Table 3 in appendix B. 

*********************************
***** Results in appendix G *****
*********************************
eststo clear 
* Column 1: Changes in left-wing advantage and growth in unemployment:
qui regress LWA NP if Year > 1998 ,  vce(cluster Id)
estadd local year "No", replace
estadd local controls "No", replace
estadd local controls2 "No", replace
estadd local trend "No", replace
estimates store LWA_OLS1

* Column 2 Multivariate regression unemployment in first diffrence:
qui reghdfe d.LWA GNE if Year > 2002, absorb(midbyyear Id) vce(cluster Id)
estadd local year "Yes",replace
estadd local controls "No", replace
estadd local controls2 "No", replace
estadd local trend "No", replace
estimates store LWA_OLS2

* Column 3 Multivariate regression relative growth rate in unemployment:
qui reghdfe d.LWA GNE d.(Migrant Education Age Agesq) if Year > 2002, absorb(midbyyear Id) vce(cluster Id)
estadd local year "Yes", replace
estadd local controls "Yes", replace
estadd local controls2 "No", replace
estadd local trend "No", replace
estimates store LWA_OLS3

* Column 4: Multivariate regression relative growth rate in unemployment:
qui reghdfe  d.LWA c.GNE##c.Net_returns d.(Migrant Education Age Agesq) cd.(Migrant Education Age Agesq )#c.Net_returns if Year > 2002 ,absorb(midbyyear i.Id) vce(cluster Id)
estadd local year "Yes", replace
estadd local controls "Yes", replace
estadd local controls2 "Yes", replace
estadd local trend "Yes", replace
estimates store LWA_OLS4

* Exporting Table 1:
esttab LWA_OLS1 LWA_OLS2 LWA_OLS3 LWA_OLS4 , se title(Unemployment and the left-wing advantage estimates)  ///
keep(NP GNE Net_returns c.GNE#c.Net_returns _cons ) ///
style(tex) star(* .10 ** .05 *** .01) mtitles("1" "2" "3" "4" "5") label  nonumbers ///
s(N year controls controls2 trend ,label("N" "Year by municipality effects" "Controls" "Controls interacted with wealth" "Districts effects")) ///
replace

************************************
********* Table 3 in appendix B ****
************************************
eststo clear
local vars SWPV1999 HWPV1999 MWPV1999 AWPV1999 DPV1999 Wealth1999 Voters LWA  Left Migrant Education NP Age  
estpost summarize `vars' if Year > 1998 & Year < 2018 & panel < 4
esttab using summarystats.tex, cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2)) count(fmt(0))") noobs nonumber label title("Summary statistics") replace
